package com.sea.base.utils

import com.sea.base.ext.global.getCurrentMillis

/**
 * 双击检测
 */
class DoubleCheck @JvmOverloads constructor(private val clickInterval: Long = 300) {
    private var lastClickMillis = 0L
    private var isCallDouble = false

    /**
     * @return true:双击了，false:单击或者连续的3/4/5/6等连击
     */
    fun isDoubleClick(): Boolean {
        val now = getCurrentMillis()
        var returnValue = false
        if (now - lastClickMillis < clickInterval) {
            if (!isCallDouble) {
                returnValue = true
            }
            isCallDouble = true
        } else {
            isCallDouble = false
        }
        lastClickMillis = now
        return returnValue
    }
}